package com.example.springboottest.initializer;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.Order;

/**
 *  三种办法添加ApplicationContextInitializer
 *  1、在spring.factories文件下，和listener类似添加
 *  2、在application.yml或properties文件下添加
 *  context:
 *   initializer:
 *     classes: com.example.springboottest.initializer.Demo1Initializer
 *  3、在启动入口类添加
 *      但这种方式会覆盖掉默认配置
 *
 *  Order值越小，越先启动
 *
 */
@Order(123)
public class Demo1Initializer implements ApplicationContextInitializer {
    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        //打印容器里面初始化了多少个Bean
        System.out.println("Demo1Initializer容器中初始化Bean数量:\t" + applicationContext.getBeanDefinitionCount());
    }
}
